(function($){
    $.fn.hoverDelay = function(options){
        var defaults = {
            hoverDuring: 500,
            outDuring: 200,
            hoverEvent: function(){
                $.noop();
            },
            outEvent: function(){
                $.noop();    
            }
        };
        var sets = $.extend(defaults,options || {});
        var hoverTimer, outTimer;
        return $(this).each(function(){
            $(this).hover(function(){
                clearTimeout(outTimer);
                hoverTimer = setTimeout(sets.hoverEvent, sets.hoverDuring);
            },function(){
                clearTimeout(hoverTimer);
                outTimer = setTimeout(sets.outEvent, sets.outDuring);
            });    
        });
    }
})(jQuery);


$(document).ready(function(){

    var delay;
    $('.subnav li').hover(function(){
        delay = $(this);
    });
    $('.subnav li').hoverDelay({
        hoverEvent:function(){
            delay.children('em').text("-");
            delay.children('dl').show(500);
        },outEvent:function(){
            delay.children('dl').hide(500);
            delay.children('em').text("+");
        }
    });
    $('.subnav li').mouseleave(function(){
        $(this).children('dl').hide(500);
        $(this).children('em').text("+");
    });

    var rollbanner = $(".bannerlist ul");
    var list_surplus = 0;
    $(".bannernext").click(function(){
        var list_length = (rollbanner.find("li").size()-1)*585;
        if(list_length > list_surplus){
            rollbanner.animate({marginLeft:'-=585px'});
            list_surplus = list_surplus + 585;
            var hotbtn_count = list_surplus/585;
            hotbtn_count = '#rollbtn'+ hotbtn_count;
            $(".bannerbtn span b").attr("class"," ");
            $(hotbtn_count).attr("class","hotbtn");
        }
        else if(list_length == list_surplus){
            list_surplus = 0;
            list_length = '+=' + list_length + 'px';
            rollbanner.animate({marginLeft:list_length});
            $(".bannerbtn span b").attr("class"," ");
            $("#rollbtn").attr("class","hotbtn");
        }
    });
    $(".bannerprve").click(function(){
        var list_length = (rollbanner.find("li").size()-1)*585;
        if(list_surplus > 0){
            rollbanner.animate({marginLeft:'+=585px'});
            list_surplus = list_surplus - 585;
            var hotbtn_count = list_surplus/585;
            hotbtn_count = '#rollbtn'+ hotbtn_count;
            $(".bannerbtn span b").attr("class"," ");
            $(hotbtn_count).attr("class","hotbtn");
        }
        else if(list_surplus == 0){
            list_surplus = list_length;
            list_length = '-=' + list_length +'px';
            rollbanner.animate({marginLeft:list_length});
            $(".bannerbtn span b").attr("class"," ");
            $(".bannerbtn").find("a:last").attr("class","hotbtn");
        }
    });
    $(".bannerbtn span b").click(function(){
        var id_name = $(this).attr("id");
        var id_num = id_name.substr(7,1)*1; 
        rollbanner.animate({'margin-left':-(id_num*585)});
        list_surplus = id_num*585;
        id_name = "#" + id_name;
        $(".bannerbtn span b").attr("class"," ");
        $(id_name).attr("class","hotbtn");
    });

    var rollbannerlist = setInterval(function(){
        $(".bannernext").click();
    },3000);

    $(".banner").hover(function(){
        clearInterval(rollbannerlist);},function(){
            rollbannerlist = setInterval(function(){$(".bannernext").click();},3000);
    });

    var rollbanner_s = $(".bannerlist_s ul");
    var list_surplus_s = 0;
    $(".bannernext_s").click(function(){
        var list_length_s = (rollbanner_s.find("li").size()-1)*190;
        if(list_length_s > list_surplus_s){
            rollbanner_s.animate({marginLeft:'-=190px'});
            list_surplus_s = list_surplus_s + 190;
            var hotbtn_count = list_surplus_s/190;
            hotbtn_count = '#rollbtn_s'+ hotbtn_count;
            $(".bannerbtn_s span b").attr("class"," ");
            $(hotbtn_count).attr("class","hotbtn");
        }
        else if(list_length_s == list_surplus_s){
            list_surplus_s = 0;
            list_length_s = '+=' + list_length_s + 'px';
            rollbanner_s.animate({marginLeft:list_length_s});
            $(".bannerbtn_s span b").attr("class"," ");
            $("#rollbtn_s").attr("class","hotbtn");
        }
    });
    $(".bannerprve_s").click(function(){
        var list_length_s = (rollbanner_s.find("li").size()-1)*190;
        if(list_surplus_s > 0){
            rollbanner_s.animate({marginLeft:'+=190px'});
            list_surplus_s = list_surplus_s - 190;
            var hotbtn_count = list_surplus_s/190;
            hotbtn_count = '#rollbtn_s'+ hotbtn_count;
            $(".bannerbtn_s span b").attr("class"," ");
            $(hotbtn_count).attr("class","hotbtn");
        }
        else if(list_surplus_s == 0){
            list_surplus_s = list_length_s;
            list_length_s = '-=' + list_length_s +'px';
            rollbanner_s.animate({marginLeft:list_length_s});
            $(".bannerbtn_s span b").attr("class"," ");
            $(".bannerbtn_s").find("a:last").attr("class","hotbtn");
        }
    });
    $(".bannerbtn_s span b").click(function(){
        var id_name = $(this).attr("id");
        var id_num = id_name.substr(7,1)*1; 
        rollbanner_s.animate({'margin-left':-(id_num*190)});
        list_surplus_s = id_num*190;
        id_name = "#" + id_name;
        $(".bannerbtn_s span b").attr("class"," ");
        $(id_name).attr("class","hotbtn");
    });

    var rollbanner_slist_s = setInterval(function(){
        $(".bannernext_s").click();
    },3000);

    $(".banner_s").hover(function(){
        clearInterval(rollbanner_slist_s);},function(){
            rollbanner_slist_s = setInterval(function(){$(".bannernext_s").click();},3000);
    });

    $(".small_img img").hover(function(){
        $(this).parent().find("img").attr("class"," ");
        $(this).attr("class","active");
        $("#spec-n1 img").attr("src",$(this).attr("src"));
        $("#spec-n1 img").attr("jqimg",$(this).attr("src"));
    });


});


$(function (){
    var x=0,width,height,ul=$(".content"),bottom=$(".bottom"),t;
    function img_block(){
        bottom.stop();
        ul.stop();
        $(".content li").css("display","none");
        bottom.css({"height":"0px"});
        $("#xz").text(x+1);
        width=parseInt($(".content li:eq("+x+")").css("width"));
        height=parseInt($(".content li:eq("+x+")").css("height"));
        ul.animate({"width":width+"px","height":height+"px"},500,function (){
            $(".content li:eq("+x+")").css("display","block");
            bottom.css("width",width+"px");
            bottom.animate({"height":"40px"});
            $(".left,.right").css({"width":width/2+"px","height":height+"px"})
            });
        };

    function rights(){
        if(x==$(".content li").length-1){x=0;}
        else{x++};
            // $(".containers").animate({"marginLeft":-($(".containers").width()/2)+"px","marginTop":-($(".containers").height()/2)+"px"},500);
        img_block();
        };

    $(".right").click(function (){rights()});

    $(".left").click(function (){
        if(x==0){x=$(".content li").length-1;}
        else{x--};
            // $(".containers").animate({"marginLeft":-($(".containers").width()/2)+"px","marginTop":-($(".containers").height()/2)+"px"},500);
        img_block();
        });

    $(".left,.right").hover(function (){clearTimeout(t)},function (){
        t=setInterval(rights,4000);
        // var left1 = $(".containers").width()/2;
        // var top1 = $(".containers").height()/2;
        // $(".containers").animate({"marginLeft":-left1+"px","marginTop":-top1+"px"},500);
    });

    $("#imgs li").click(function() {
        // $(".containers").attr("style","margin-left:" + (-($(".containers").width()/2)) + "px;" + "margin-top:" + (-($(".containers").height()/2)) + "px;");
        $(".container").attr("style","display:block;");
        x = $(this).index();
        $("#imgdata").text($(".content li").length);
        img_block();
        t=setInterval(rights,4000);
    });

    $(".bottom em.fr").click(function(){
        $(".container").attr("style","display:none;");
        clearTimeout(t);
    });
});